﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace Rapid.MvcExtension.Controls.Manage
{
    public static class IncludeFile
    {
        /// <summary>
        /// 样式
        /// </summary>
        /// <param name="src"></param>
        /// <returns></returns>
        public static MvcHtmlString Style(string path, string src)
        {
            path = path.Substring(0, path.LastIndexOf("/") + 1) + src;

            string filepath = HttpContext.Current.Server.MapPath(path);

            string styles = string.Empty;

            if (File.Exists(filepath))
            {
                using (StreamReader sr = new StreamReader(filepath))
                {
                    styles = sr.ReadToEnd();
                }
            }

            return new MvcHtmlString("<style type=\"text/css\">" + styles + "</style>");
        }

        /// <summary>
        /// 脚本
        /// </summary>
        /// <param name="src"></param>
        /// <returns></returns>
        public static MvcHtmlString Script(string path, string src)
        {
            path = path.Substring(0, path.LastIndexOf("/") + 1) + src;

            string filepath = HttpContext.Current.Server.MapPath(path);

            string javascript = string.Empty;

            if (File.Exists(filepath))
            {
                using (StreamReader sr = new StreamReader(filepath))
                {
                    javascript = sr.ReadToEnd();
                }
            }

            return new MvcHtmlString("<script type=\"text/javascript\">" + javascript + "</script>");
        }
    }
}